package com.pocket.demo.core.security.oauth2;

import com.nimbusds.jose.jwk.source.JWKSource;
import com.nimbusds.jose.proc.SecurityContext;
import jakarta.annotation.Resource;
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider;

/**
 * @author zhaozhile
 */
//@Configuration
//@Import(OAuth2ResourceServerAutoConfiguration.class)
//@Import(OAuth2ResourceServerConfigurer.class)
public class AuthorizationResourceConfig {

    /**
     * Jwt 解码器。用于解码签名访问令牌（access token），给 资源服务 使用
     */
    public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
        return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
    }

    @Resource
    private JwtDecoder jwkDecoder;

    //@Bean
    public JwtAuthenticationProvider jwtAuthenticationProvider() {
        return new JwtAuthenticationProvider(jwkDecoder);
    }

}
